﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DbCreater1
{
    class Program
    {

        static void Main(string[] args)
        {
            DoCreate();
            //以下用于进行测试
            //PropertyInfo[] propertyInfos = typeof(Model.DbTest).GetProperties();

            //foreach (var item in propertyInfos)
            //{
            //    DescriptionAttribute dsa = item.GetCustomAttribute<DescriptionAttribute>();
            //    if(dsa!=null)
            //    Console.WriteLine(dsa.Description);
            //}
            //Console.ReadKey();
        }

        private static void DoCreate()
        {
            string constr = "Server=103.236.252.103; Port=3306; Database=PassionIms; Uid=PassionIms; Pwd=pims20200515;Charset=utf8;Convert Zero Datetime=True;Allow Zero Datetime=True;Pooling=true;Max Pool Size=1024;Min Pool Size=1;Allow User Variables=True;";//示例
            string targets = Path.Combine(Environment.CurrentDirectory, "DatabaseMigration.dll");         
            string dbtype = "MySql";
            string arg = $" /conn \"{constr}\" /provider {dbtype} /assembly \"{targets}\" ";///task \"{tsk}\" /namespace \"{nsp}\" /timeout=90";

            string runnerExe = Path.Combine(Environment.CurrentDirectory, "tools", "Migrate.exe");

            Process process = new Process();
            process.StartInfo.FileName = "cmd.exe";

            process.StartInfo.UseShellExecute = false;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = false;
            process.Start();
            process.StandardInput.WriteLine(runnerExe + " " + arg);
            process.WaitForExit();
        }
    }
}
